home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / STANDALO / DB6 / SHIFTKEY.C < prev   
C/C++ Source or Header  |  1990-10-26  |  3KB  |  97 lines

  1.  
  2. /****************************************************/
  3. /*                                                    */
  4. /*    XFCN for MichrophoneII to tell whether the        */
  5. /*    user has the Shift key pressed.                    */
  6. /*    Written by Don Bachner ⌐ October 1990            */
  7. /*    Free to all except for resale                    */
  8. /*                                                    */
  9. /****************************************************/
  10.  
  11. #include "HyperXCmd.h"
  12. #include <string.h>
  13.  
  14. /*********************************** GlobalDefines ***********************/
  15. #define MIN_SLEEP            0L
  16. #define    NIL_MOUSE_REGION    0L
  17. #define    WNE_TRAP_NUM        0x60
  18. #define    UNIMPL_TRAP_NUM        0x9F
  19.  
  20.  
  21. /*********************************** Prototypes ************************/
  22. pascal void     main            (XCmdBlockPtr);
  23.  
  24. Handle            CopyStrToHand    ( char*);
  25.  
  26.  
  27. /******************************** main *********/
  28.  
  29. pascal void 
  30. main( XCmdBlockPtr  paramPtr )
  31.  
  32. {
  33.     Boolean            eventHappened,WNEImplemented;
  34.     EventRecord        theEvent;
  35.     short            i;
  36.     
  37.     WNEImplemented= (NGetTrapAddress( WNE_TRAP_NUM,ToolTrap )!=
  38.             NGetTrapAddress(UNIMPL_TRAP_NUM, ToolTrap ) );
  39.             
  40.     if( WNEImplemented )
  41.         eventHappened=WaitNextEvent( everyEvent,&theEvent,MIN_SLEEP,NIL_MOUSE_REGION );
  42.     else
  43.     {
  44.         SystemTask();
  45.         eventHappened=GetNextEvent( everyEvent, &theEvent );
  46.     }        
  47.     
  48.     /*Since MichII traps for mousedowns and looks to the modifiers field for the    */
  49.     /*command or option key, this will flush those events(mouseDown/KeyDown).        */
  50.     /*Thus, using mouseUp (which is just sitting there minding it's own business in    */
  51.     /*the event que-very lonely) is the way to go!!                                    */
  52.      
  53.      
  54.     if (eventHappened)  
  55.     {
  56.         
  57.             switch ( theEvent.what )
  58.             {    
  59.                 case keyDown:  /*These are here for no good reason, really!*/
  60.                 case autoKey:
  61.                 
  62.                     if( (theEvent.modifiers & shiftKey ) !=0)
  63.                         paramPtr->returnValue = (Handle)CopyStrToHand("true" );
  64.                     break;
  65.                 
  66.                 case mouseUp:   /*This will always be trapped*/
  67.                  
  68.                     if( (theEvent.modifiers & shiftKey ) !=0)
  69.                         paramPtr->returnValue = (Handle)CopyStrToHand("true" );
  70.                     else
  71.                         paramPtr->returnValue = (Handle)CopyStrToHand("false" );
  72.                     break;
  73.                 
  74.                 default:/*Not really needed, but just in case you really need 'false'*/
  75.                 
  76.                     paramPtr->returnValue = (Handle)CopyStrToHand("false" );
  77.                     break;
  78.             }
  79.                 
  80.     }
  81.  
  82.     return;
  83. }
  84.  
  85. /*********************************** CopyStrToHand ***********************/
  86. Handle
  87. CopyStrToHand(char    *str)
  88. {
  89.     Handle        resultHandle;
  90.     
  91.     resultHandle= NewHandle((long)strlen(str) +1); /*Add one for 0 termination*/
  92.     strcpy((char*)(*resultHandle),str);
  93.     return(resultHandle);
  94. }
  95.  
  96.  
  97. /****END ShiftKey() October 23, 1990****/